<!-- 表单弹窗 -->
<form id="dept-form" lay-filter="dept-form" class="layui-form layui-form-pane" style="padding: 15px 15px 0px 15px">
    <input name="pid" type="hidden"/>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>上级部门</label>
        <div class="layui-input-block">
            <!-- <input type="text" name="parentId" placeholder="请选择上级部门" autocomplete="off"
            	 class="layui-input" readonly="readonly" style="background-color: #f2f2f2;">  -->
           	 <input type="text" name="parentId" id="tree" lay-filter="tree" class="layui-input"/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>部门名称</label>
        <div class="layui-input-block">
            <input name="deptName" placeholder="请输入部门名称" type="text" class="layui-input" maxlength="20"
                   lay-verify="required" required/>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">显示排序</label>
        <div class="layui-input-block">
            <input type="text" name="sortOrder" lay-verify="number" placeholder="请输入排序号" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">负责人</label>
        <div class="layui-input-block">
            <input name="leader" placeholder="请输入负责人" type="text" class="layui-input" maxlength="20" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话</label>
        <div class="layui-input-block">
            <input type="text" name="phone" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="text" name="email" placeholder="请输入邮箱" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" pane>
        <label class="layui-form-label"><i class="layui-icon required">&#xe642;</i>是否启用</label>
        <div class="layui-input-block">
            <input type="radio" name="isEnable" value="1" title="是" checked/>
            <input type="radio" name="isEnable" value="0" title="否"/>
        </div>
    </div>
    <div class="layui-form-item model-form-footer">
        <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog"><i class="layui-icon">&#x1006;</i> 取消</button>
        <button class="layui-btn" lay-filter="dept-form-submit" lay-submit><i class="layui-icon">&#xe605;</i> 保存</button>
    </div>
</form>

<script th:inline="javascript">
/*<![CDATA[*/
    layui.use(['layer', 'jquery', 'sadmin', 'form', 'treeSelect'], function () {
        var $ = layui.$ //重点处
        var layer = layui.layer;
        var sadmin = layui.sadmin;
        var form = layui.form;
        var treeSelect = layui.treeSelect;

        form.render('radio');

        // 回显dept数据
        var dept = sadmin.getTempData('system_dept');
        treeSelect.render({
            // 选择器
            elem: '#tree',
            // 数据
            data: 'system/dept/deptTree',
            // 异步加载方式：get/post，默认get
            type: 'get',
            // 占位符
            placeholder: '请选择上级部门',
            // 是否开启搜索功能：true/false，默认false
            search: true,
            // 一些可定制的样式
            style: {
                folder: {
                    enable: true
                },
                line: {
                    enable: true
                }
            },
            // 点击回调
            click: function(d){
                console.log(d.current.id);
                $('input[name="parentId"]').val(d.current.id);
            },
            // 加载完成后的回调函数
            success: function (d) {
            	if (dept) {
            		treeSelect.checkNode('tree', dept.parentId);
            	}
            }
        });
        
        var url = 'system/dept/save';
        if (dept) {
            form.val('dept-form', dept);
        }

        // 表单提交事件
        form.on('submit(dept-form-submit)', function (data) {
            layer.load(2);
            $.post(url, data.field, function (result) {
                layer.closeAll('loading');
                layer.msg(result.msg);
                sadmin.finishPopupCenter();
            });
            return false;
        });
    });
/*]]>*/
</script>